package com.open.capacity.finance.service.impl;

import com.open.capacity.finance.util.uuid.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.open.capacity.commons.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.open.capacity.commons.CodeEnum;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.MapUtils;

import com.open.capacity.finance.entity.SourceImport;
import com.open.capacity.finance.dao.SourceImportDao;
import com.open.capacity.finance.service.SourceImportService;


@Service
public class SourceImportServiceImpl  implements SourceImportService {

    @Autowired
    private SourceImportDao sourceImportDao;

    /**
     * 添加
     * @param sourceImport
     */
    public int save(SourceImport sourceImport){
        sourceImport.setId(UUIDUtils.getOriginalUUIDWithoutBar());
    	  return sourceImportDao.save(sourceImport);
    }

    /**
     * 修改
     * @param sourceImport
     */
    public int update(SourceImport sourceImport){
        return sourceImportDao.update(sourceImport);
    }


    /**
     * 删除
     * @param id
     */
    public int delete(String id){
        return sourceImportDao.delete(id);
    }

    /**
     * 查询记录
     * @param id
     * @return
     */
    public SourceImport findById(String id){
        return sourceImportDao.findById(id);
    }

    /**
     * 分页
     * @param params
     * @return
     */
    public PageResult<SourceImport> pageAll(Map<String, Object> params){
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        if (MapUtils.getInteger(params, "page")!=null && MapUtils.getInteger(params, "limit")!=null)
            PageHelper.startPage(MapUtils.getInteger(params, "page"),MapUtils.getInteger(params, "limit"),true);

        List<SourceImport> list  =  sourceImportDao.findAll(params);
        PageInfo<SourceImport> pageInfo = new PageInfo(list);

        return PageResult.<SourceImport>builder().data(pageInfo.getList()).resp_code(CodeEnum.SUCCESS.getCode()).count(pageInfo.getTotal()).build();
    }

    /**
    * 列表
    * @param params
    * @return
    */
    public List<SourceImport> findAll(Map<String, Object> params){
        return  sourceImportDao.findAll(params);
    }

}
